|
|
import josx.platform.rcx.*;
import josx.robotics.*;
class AdjustDirection implements Behavior {
public Sensor sensor = Sensor.S2;
public boolean takeControl(){
if (sensor.readValue() > 45 || sensor.readValue() < 42)
return true;
else return false;
}
public void suppress() {}
public void action() {
if (sensor.readValue() > 45) {
Motor.C.backward(); Motor.A.forward();
try { Thread.sleep(30);} catch (Exception e){}
}
if (sensor.readValue() < 42) {
Motor.A.backward(); Motor.C.forward();
try { Thread.sleep(30);} catch (Exception e){}
} } }
AdjustDirection only takes control when the sensor reading is outside of the 42-45 range
When it takes control, it runs the action method, which then runs and returns to the Arbitrator class.
The Arbitrator will then continue cycling through the available behaviors and find one who's take control method is true
|
|